﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Ecreate.Web.usercontrol
{
    public partial class ucProductList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string single = "<div class=\"pictable_R_2\" xmlns=\"\"><div class=\"fl leftpart\"><a class=\"list_product_image\" href=\"{0}\" target=\"_blank\">"
                + "<img style=\"margin-top:-5px;\" class=\"mg_b fl\" alt=\"{1}\" src=\"{2}\" width=127 height=127></a>"
                + "<h3><a href=\"{0}\" target=\"_blank\">{1}</a></h3>"
                + "<div class=\"money_new pd_B\">价格：￥{3}</div></div></div>";
            //0:图片链接地址;1:产品名称;2:图片位置;3:价格
            string stype = Request.QueryString["type"].ToString();
            string sql = "select * from t_product where isdown='0'";
            string where = " ";
            if (stype == "c2")//littleclass
            {
                string id = Request.QueryString["id"].ToString();
                where = " and classid='" + id + "'";
            }
            else if (stype == "ht")//hot
            {
                where = " and ishot='1'";
            }
            else if (stype == "sl")//sale
            {
                where = " and issale='1'";
            }
            else if (stype == "sc")//search
            {
                string cl = Request.QueryString["cl"].ToString();
                string txt = Request.QueryString["txt"].ToString();
                if (cl == "c1")
                {
                    where = " and classid in (select classid from t_product_class where parentclassid in (select classid from t_product_class where flevel=0 and classname like '%" + txt + "%'))";
                }
                else if (cl == "c2")
                {
                    where = " and classid in (select classid from t_product_class where flevel=1 and classname like '%" + txt + "%')";
                }
                else if (cl == "nm")
                {
                    where = " and pname like '%" + txt + "%'";
                }
            }
            DataTable dt = GG.GetTable(sql + where);
            string items = "";
            foreach (DataRow dr in dt.Rows)
            {
                string s1 = "ProductPage.aspx?pid=" + dr["pid"].ToString();
                //s1 = string.Format(onclick, new string[] { s1 });
                string s2 = dr["pname"].ToString();
                string s3 = dr["pimageurl"].ToString();
                string s4 = dr["price"].ToString();
                items += string.Format(single, new string[] { s1, s2, s3, s4 });
            }
            Literal1.Text = items;
        }
    }
}